package com.woniu.cms.finance.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.woniu.cms.finance.core.entity.FinanceAccounting;
import com.woniu.cms.finance.core.mapper.FinanceAccountingMapper;
import com.woniu.cms.finance.core.service.IFinanceAccountingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.cms.finance.core.vo.GetAccountingVo;
import com.woniu.common.api.Result;
import com.woniu.common.api.status.Impl.BusinessCode;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 项目列帐总表 服务实现类
 * </p>
 *
 * @author kiron
 * @since 2022-09-19
 */
@Service
public class FinanceAccountingServiceImpl extends ServiceImpl<FinanceAccountingMapper, FinanceAccounting> implements IFinanceAccountingService {
    private FinanceAccountingMapper financeAccountingMapper;

    @Override
    public Result getList() {
        List<FinanceAccounting> count = financeAccountingMapper.getCount();
        Map map = new HashMap();
        map.put("data",count);
        Result<Map> common = Result.common(map);
        return common;
    }

    @Override
    public Result addAccounting(List<FinanceAccounting> financeAccounting) {
        boolean b = this.saveBatch(financeAccounting);
        if(!b){
            return Result.error(BusinessCode.MODIFY_FAIL);
        }
        return Result.ok(BusinessCode.ADD_SUCCESS);
    }

    @Override
    public Result deleteAccounting(List<FinanceAccounting> financeAccountings) {
        for (FinanceAccounting financeAccounting : financeAccountings) {
            if(financeAccounting.getAccountingStatus()==1 || financeAccounting.getAccountingStatus()==2){
                return Result.error(BusinessCode.REMOVE_FAIL);
            }
        }
        boolean b = this.removeBatchByIds(financeAccountings);
        if(!b){
            return Result.error(BusinessCode.REMOVE_FAIL);
        }
        return Result.ok(BusinessCode.REMOVE_SUCCESS);
    }

    @Override
    public Result getAll(Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize).doSelectPage(()->financeAccountingMapper.getAll());
 return null;
    }
}
